<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

function get_path($file, $path) 
{			
	$CI =& get_instance();
	//$theme = $CI->_data['theme'];
	$lg = $CI->_data['lang'];
	
//	if ($theme!=FALSE)
//	{
//		$theme_path = 'assets/themes/'.$theme.'/'.$path.'/';
//		$file_lang = $theme_path.$lg.'/'.$file;
//		if (file_exists($file_lang))
//		{
//			return base_url().$file_lang;
//		}
//		elseif (file_exists($theme_path.'/'.$file))
//		{
//			return base_url().$theme_path.'/'.$file;
//		}		
//	}
		
	$file_lang = 'assets/'.$path.'/'.$lg.'/'.$file;
	if (file_exists($file_lang))
	{
		return base_url().$file_lang;
	}
	else
	{
		return base_url().'assets/'.$path.'/'.$file;
	}	
}

// ------------------------------------------------------------------------

function style($file, $path='css', $attributes = '')
{
	if (empty($file)) return;	
	return '<link type="text/css" rel="stylesheet" href="'. get_path($file, $path) .'" '.$attributes.' />' . "\n";	
}

function script($file, $path='js')
{
	if (empty($file)) return;
	return '<script src="'. get_path($file, $path) .'" type="text/javascript" charset="utf-8"></script>' . "\n";
}

function image($file, $path='img', $attributes = '')
{
	if (empty($file)) return;	
	return '<img src="'. get_path($file, $path) .'" '.$attributes.' />' . "\n";	
}

function hmenu($current, $names, $links)
{	
	$base_url = site_url('/');
	$out = '<ul>';
	for ($i=0;$i<count($names);$i++)
	{		
		if ($i==$current)
		{
			$out .= '<li class="active">';
		}
		else
		{
			$out .= '<li>';
			if (($i!=$current+1)&&($i!=0))
			{
				$out .= '<span>&nbsp;</span>';
			}
			if ($i==0)
			{
				$out .= '<span style="background:none">&nbsp;</span>';
			}
		}
		$out .= '<a href="'.$base_url.$links[$i].'" title="">'.$names[$i].'</a>';
		$out .= '</li>';
	}
	$out .= '</ul>';	
    return $out;
}

function vmenu($hmenu_index, $root_id, $base_link=null, $lv=1, $class='cate')
{
        $CI =& get_instance();
        if (!$base_link)
        {
            $base_link = site_url('product/plist');
        }        
        $data = $CI->category->get_child_vmenu($root_id,$CI->_data['lang_view']);
        $t = '';
        foreach ($data as $item)
        {
            $t .= '<a href="'.$base_link.'/'.$hmenu_index.'/'.$item['id_category'].'" class="cate'.$lv.'">'.$item['name'].'</a>' ;
            $t .= vmenu($hmenu_index, $item['id_category'], $base_link, $lv+1);
        }
        return $t;
}

function vnd_format($price)
{    
    $price = round($price,-2);
    return number_format($price, -2, '.', ',');
}

function get_product_breadcrum($id_root, $id_leaf, $base_link)
{    
    $CI =& get_instance();    
    $cate = $CI->category->get_detail($id_leaf, $CI->_data['lang_view']);
    if ($cate->depth==0) return;
    if ($id_root!=$id_leaf)        
    {
        get_product_breadcrum($id_root,$cate->id_parent, $base_link);
    }   
    $CI->_data['breadcrumbs'][] = array(
        'name' => $cate->name,
        'link' => $base_link.$cate->id_category
    );	           
}


function change_language($lang_id) {
        $CI =& get_instance();                
        if ($lang_id == 1) {
            $this->session->set_userdata('lang_view', 1);
            $lang = 'english';
        } else {
            $this->session->set_userdata('lang_view', 2);
            $lang = 'vi';
        }    
        $this->CI->_data['lang'] = $lang;
        $this->CI->_data['lang_view'] = $lang_id;
}

function get_product_link($product_id, $slug) {
    $CI =& get_instance();
    return site_url('product').'/'. $CI->_data['lang_view'].'/'.$product_id.'/'.$slug;
}

// EOF
?>